package written_examination;
import java.util.*;

public class Main_1124_2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        StringBuffer sb = new StringBuffer();
        String table = "0123456789ABCDEF";
        boolean flag = true;
        if(m < 0){
            m = -m;
            flag = false;
        }
        if(m == 0){
            sb.append('0');
        }
        while(m != 0){
            sb.append(table.charAt(m % n));
            m = m / n;
        }
        if(!flag){
            sb.append('-');
        }
        sb.reverse();
        System.out.println(sb);
    }
}
